# 视频转语音服务配置

import os
from typing import List
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    """
    视频转语音服务配置类
    """
    # 项目基本信息
    PROJECT_NAME: str = "视频转语音服务"
    PROJECT_DESCRIPTION: str = "提供高效的视频转语音API服务"
    VERSION: str = "0.1.0"
    API_PREFIX: str = "/api/v1"
    
    # CORS配置
    CORS_ORIGINS: str = "http://localhost:3000"
    
    @property
    def cors_origins_list(self) -> List[str]:
        """将CORS_ORIGINS字符串转换为列表"""
        if isinstance(self.CORS_ORIGINS, str):
            return [origin.strip() for origin in self.CORS_ORIGINS.split(",")]
        return self.CORS_ORIGINS

    # 视频处理配置
    MAX_VIDEO_SIZE_MB: int = 500  # 最大视频文件大小(MB)
    SUPPORTED_VIDEO_FORMATS: List[str] = ["mp4", "avi", "mov", "mkv", "webm"]
    TEMP_UPLOAD_DIR: str = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "uploads")
    OUTPUT_DIR: str = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "output")
    
    # 语音合成配置
    DEFAULT_LANGUAGE: str = "zh"  # 默认语音语言
    SUPPORTED_LANGUAGES: List[str] = ["zh", "en", "ja", "ko", "fr", "de", "es"]
    DEFAULT_TTS_SPEED: float = 1.0  # 默认语速
    
    # 语言代码映射（支持完整的语言代码）
    LANGUAGE_CODE_MAPPING: dict = {
        "zh-CN": "zh",
        "zh-TW": "zh", 
        "en-US": "en",
        "en-GB": "en",
        "ja-JP": "ja",
        "ko-KR": "ko",
        "fr-FR": "fr",
        "de-DE": "de",
        "es-ES": "es"
    }
    
    # 安全配置
    API_KEY_HEADER: str = "X-API-Key"
    API_KEY: str = os.getenv("API_KEY", "")
    
    model_config = {
        "case_sensitive": True,
        "env_file": ".env"
    }

# 创建全局设置实例
settings = Settings()

# 确保临时目录存在
os.makedirs(settings.TEMP_UPLOAD_DIR, exist_ok=True)
os.makedirs(settings.OUTPUT_DIR, exist_ok=True)